package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.uuid.UUIDUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;

    // 新增线索跟进记录
    @Override
    public int add(ClueTrackRecordVo clueTrackRecordVo) {
        TbClueTrackRecord trackRecord = new TbClueTrackRecord();
        trackRecord.setClueId(clueTrackRecordVo.getClueId()); // 线索id
        trackRecord.setLevel(clueTrackRecordVo.getLevel()); // 意向等级
        trackRecord.setRecord(clueTrackRecordVo.getRecord()); // 跟进记录
        trackRecord.setSubject(clueTrackRecordVo.getSubject()); // 意向学科
        trackRecord.setNextTime(clueTrackRecordVo.getNextTime()); // 下次跟进时间
        trackRecord.setType(clueTrackRecordVo.getType()); // 跟进状态
        trackRecord.setFalseReason(clueTrackRecordVo.getFalseReason()); // 踢回线索池原因
        trackRecord.setCreateBy(SecurityUtils.getUsername());// 创建人
        trackRecord.setCreateTime(DateUtils.getNowDate()); // 创建时间


        TbClue tbClue = new TbClue();
        tbClue.setAge(clueTrackRecordVo.getAge()); // 年龄
        tbClue.setName(clueTrackRecordVo.getName()); // 姓名
        tbClue.setSex(clueTrackRecordVo.getSex()); // 性别
        tbClue.setQq(clueTrackRecordVo.getQq()); // qq
        tbClue.setWeixin(clueTrackRecordVo.getWeixin()); // 微信
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue()); // 线索状态
        tbClue.setId(clueTrackRecordVo.getClueId()); // 线索id

        tbClueMapper.updateTbClue(tbClue); // 更新线索表
        return tbClueTrackRecordMapper.add(trackRecord); // 添加线索跟进

    }


    // 查询线索跟进表
    @Override
    public List<TbClueTrackRecord> findListByClueId(Long clueId) {
        return tbClueTrackRecordMapper.findListByClueId(clueId);
    }
}
